//==============================================================================
//
// File: ServerInfoDialog.cpp
// Project: Browser
// Author(s): Matthias Van Eeghem (matthias@van-eeghem.com)
// License: See LICENSE in root directory
//
// This dialog is shown when a user double clicks a server in the internet
// or favorites list. It shows a bit more information about a server and
// has a "Connect" button to connect to the server
//
//==============================================================================

#include "ServerInfoDialog.h"
#include "ui_ServerInfoDialog.h"
#include "CBrowser.h"

// The constructor
ServerInfo::ServerInfo(QWidget * parent, CServer server) : QDialog(parent), ui(new Ui::ServerInfo)
{
    ui->setupUi(this);

    // Disable the icon and close button, looks nicer
    setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint);

    // Save the server object
    m_Server = server;

    // Initialise the labels
    ui->ipLabel->setText("<b>IP</b>: " + server.m_sIP + ":" + server.m_sPort);
    ui->playersLabel->setText("<b>Players</b>: " + QString::number(server.m_iPlayers) + "/" + QString::number(server.m_iMaxPlayers));
    ui->versionLabel->setText("<b>Version</b>: " + server.m_sVersion);
    ui->hostnameLabel->setText("<b>Hostname</b>: " + server.m_sHostname);
}

// Called when the "Connect" button is clicked
void ServerInfo::on_connectButton_clicked()
{
    QSettings settings;
    QString PlayerName = settings.value("PlayerName").value<QString>();

    // Launch the game
    CBrowser::LaunchGame(m_Server.m_sIP, m_Server.m_sPort, PlayerName);
}

// Called when the "Cancel" button is clicked
void ServerInfo::on_cancelButton_clicked()
{
    close();
}

ServerInfo::~ServerInfo()
{
    delete ui;
}
